﻿using System.Collections.Generic;
using System.IO;
using System.Text;

namespace LingDong.CommonUtility
{
    public class Utility
    {
        public static void AddItemCount<T>(Dictionary<T, int> dic, T item)
        {
            int curCount;
            if (dic.TryGetValue(item, out curCount))
                dic[item]= curCount + 1;
            else
                dic[item] = 1;
        }

        public static void AddItemCount<T>(Dictionary<T, List<int>> dic, T item, int value)
        {
            List<int> oldList;
            if (!dic.TryGetValue(item, out oldList))
                oldList = new List<int>();
             
            oldList.Add(value);
            dic[item] = oldList;
        }

        public static string GetFileContent(string file)
        {
            return GetFileContent(file, Encoding.Default);
        }

        public static string GetFileContent(string file, Encoding encode)
        {
            string content;
            using (StreamReader sr = new StreamReader(file, encode))
            {
                content = sr.ReadToEnd();
            }
            return content;
        }
    }
}
